package com.dingwen.treasure.base.convert;

import com.dingwen.treasure.base.annotation.Desensitization;
import com.dingwen.treasure.base.convert.serializer.DesensitizationSerializer;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
import lombok.RequiredArgsConstructor;
import org.springframework.util.ObjectUtils;

/**
 * 　DesensitizationAnnotationIntrospector
 * 　@author dingwen
 * 　@date 2022/7/20
 */
@RequiredArgsConstructor
public class DesensitizationAnnotationIntrospector extends NopAnnotationIntrospector {

    private static final long serialVersionUID = 6038096028300452691L;

    @Override
    public Object findSerializer(Annotated am) {
        Desensitization annotation = am.getAnnotation(Desensitization.class);
        if (!ObjectUtils.isEmpty(annotation)) {
            return new DesensitizationSerializer(annotation.func().getDesensitizationService());
        }
        return null;
    }
}
